package com.bishe.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bishe.entity.RolePermission;
import com.bishe.mapper.RolePermissionMapper;
import com.bishe.service.RolePermissionService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author wwz
* @description 针对表【role_permission(角色权限中间表)】的数据库操作Service实现
* @createDate 2024-03-04 13:57:33
*/
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission>
    implements RolePermissionService {

    @Override
    public List<String> getPcodeByRid(long roleId) {
        return list(new LambdaQueryWrapper<RolePermission>()
                .eq(RolePermission::getRoleId, roleId))
                .stream()
                .map(RolePermission::getPermissionCode)
                .collect(Collectors.toList());
    }

    @Override
    public List<String> selectLoginCode() {
        return list(new LambdaQueryWrapper<RolePermission>()
                .eq(RolePermission::getRoleId, StpUtil.getLoginIdAsString()))
                .stream()
                .map(RolePermission::getPermissionCode)
                .collect(Collectors.toList());
    }
}




